﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Countries.aspx.cs" Inherits="Countries.Countries" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="formMain" runat="server">
    <div>
    
    </div>
    <asp:ListBox ID="ListBox1" runat="server" DataSourceID="Contitnets" 
        DataTextField="ContinentName" DataValueField="ContinentId" AutoPostBack="true"></asp:ListBox>
    <asp:EntityDataSource ID="Contitnets" runat="server" 
        ConnectionString="name=CountriesEntities" 
        DefaultContainerName="CountriesEntities" EnableFlattening="False" 
        EntitySetName="Continents">
    </asp:EntityDataSource>

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ContryId" 
        DataSourceID="Conutries" AutoGenerateDeleteButton="True" 
        AutoGenerateEditButton="True">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="ContinentId" HeaderText="ContinentId" 
                SortExpression="ContinentId" />
            <asp:BoundField DataField="CountryName" HeaderText="CountryName" 
                SortExpression="CountryName" />
        </Columns>
    </asp:GridView>

    <asp:ListView ID="ListView1" runat="server" DataSourceID="TownsDataSource" 
        DataKeyNames="TownId" InsertItemPosition="LastItem">
        <AlternatingItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="TownIdLabel" runat="server" Text='<%# Eval("TownId") %>' />
                </td>
                <td>
                    <asp:Label ID="ContryIdLabel" runat="server" Text='<%# Eval("ContryId") %>' />
                </td>
                <td>
                    <asp:Label ID="TownNameLabel" runat="server" Text='<%# Eval("TownName") %>' />
                </td>
                <td>
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                </td>
                <td>
                    <asp:Label ID="TownIdLabel1" runat="server" Text='<%# Eval("TownId") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ContryIdTextBox" runat="server" 
                        Text='<%# Bind("ContryId") %>' />
                </td>
                <td>
                    <asp:TextBox ID="TownNameTextBox" runat="server" 
                        Text='<%# Bind("TownName") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' />
                </td>
            </tr>
        </EditItemTemplate>
        <EmptyDataTemplate>
            <table runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>
                <td>
                    <asp:TextBox ID="TownIdTextBox" runat="server" Text='<%# Bind("TownId") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ContryIdTextBox" runat="server" 
                        Text='<%# Bind("ContryId") %>' />
                </td>
                <td>
                    <asp:TextBox ID="TownNameTextBox" runat="server" 
                        Text='<%# Bind("TownName") %>' />
                </td>
                <td>
                    <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' />
                </td>
            </tr>
        </InsertItemTemplate>
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="TownIdLabel" runat="server" Text='<%# Eval("TownId") %>' />
                </td>
                <td>
                    <asp:Label ID="ContryIdLabel" runat="server" Text='<%# Eval("ContryId") %>' />
                </td>
                <td>
                    <asp:Label ID="TownNameLabel" runat="server" Text='<%# Eval("TownName") %>' />
                </td>
                <td>
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                </td>
            </tr>
        </ItemTemplate>
        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                            <tr runat="server" style="">
                                <th runat="server">
                                    </th>
                                <th runat="server">
                                    TownId</th>
                                <th runat="server">
                                    ContryId</th>
                                <th runat="server">
                                    TownName</th>
                                <th runat="server">
                                    Country</th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" style="">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                    ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <SelectedItemTemplate>
            <tr style="">
                <td>
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                </td>
                <td>
                    <asp:Label ID="TownIdLabel" runat="server" Text='<%# Eval("TownId") %>' />
                </td>
                <td>
                    <asp:Label ID="ContryIdLabel" runat="server" Text='<%# Eval("ContryId") %>' />
                </td>
                <td>
                    <asp:Label ID="TownNameLabel" runat="server" Text='<%# Eval("TownName") %>' />
                </td>
                <td>
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>

    <asp:EntityDataSource ID="TownsDataSource" runat="server" 
        ConnectionString="name=CountriesEntities" 
        DefaultContainerName="CountriesEntities" EnableFlattening="False" 
        EntitySetName="Towns" Where="it.[ContryId] = @countryId" 
        EnableDelete="True" EnableInsert="True" EnableUpdate="True">
        <WhereParameters>
            <asp:ControlParameter type="Int32" Name="countryId" ControlID="GridView1" DefaultValue="0"/> 
        </WhereParameters>
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="Conutries" runat="server" 
        ConnectionString="name=CountriesEntities" 
        DefaultContainerName="CountriesEntities" EnableFlattening="False" 
        EnableInsert="True" EnableUpdate="True" EntitySetName="Countries" 
        EntityTypeFilter="" Select="" Where="it.[ContinentId] = @contId">
        <WhereParameters>
            <asp:ControlParameter type="Int32" Name="contId" ControlID="ListBox1" DefaultValue="2"/> 
        </WhereParameters>
    </asp:EntityDataSource>
    </form>
</body>
</html>
